/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-19 20:26:18
 * @LastEditTime: 2019-11-08 11:24:16
 * @LastEditors: Please set LastEditors
 */
import axios from 'axios'
import config from '../config/config'

// const api_url = 'http://packs.test/api/';
// axios 配置
axios.defaults.timeout = 30000

// 测试地址
axios.defaults.baseURL = config.BASE_URL

// POST传参序列化
axios.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = 'application/json'
    // 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
    config.headers['Authorization'] = 'Bearer ' + localStorage.getItem('_token')
    config.headers['Access-Control-Allow-Origin'] = 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'
    if (config.method === 'post') {
      config.data = JSON.stringify(config.data)
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
export function delCookie(c_name) {
  // setCookie(c_name, '', -1)
}
export function fetch(options) {
  return new Promise((resolve, reject) => {
    if (!options.method) {
      options.method = 'post'
    }
    axios(options)
      .then(
        response => {
          if (response.data.access_token) {
            localStorage.setItem('_token', response.data.access_token)
          }
          if (response.data.status_code === '401') {
            this.$notify.error({
              title: '错误',
              message: '网络异常！请退出登录！'
            })
            delCookie('Admin-Token')
          }
          resolve(response.data)
        },
        err => {
          reject(err)
        }
      )
      .catch(error => {
        reject(error)
      })
  })
}

export default {
  login(data) {
    return fetch({
      url: '/login',
      data: data
    })
  },
  getChannel(data) {
    return fetch({
      url: '/channel_list',
      data: data
    })
  },
  exec_bat(data) {
    return fetch({
      url: 'exec_bat',
      data: data
    })
  },
  addChannel(data) {
    return fetch({
      url: '/add_channel',
      data: data
    })
  },
  add_params(data) {
    return fetch({
      url: '/save_param',
      data: data
    })
  },
  get_channel(data) {
    return fetch({
      url: '/get_channel',
      data: data
    })
  },
  view_params(data) {
    return fetch({
      url: '/view_params',
      data: data
    })
  },
  get_params_list(data) {
    return fetch({
      url: '/params/list'

    })
  },
  // 获取游戏列表
  get_game_list(data) {
    return fetch({
      url: '/game/list',
      data: data
    })
  },
  get_game_info(data) {
    return fetch({
      url: '/game/info',
      data: data
    })
  },
  add_game(data) {
    return fetch({
      url: '/game/add',
      data: data
    })
  },
  get_user_list(data) {
    return fetch({
      url: '/user/list',
      data: data
    })
  },
  add_users(data) {
    return fetch({
      url: '/user/adds',
      data: data
    })
  },
  // 获取权限父级列表
  get_permission_f(data) {
    return fetch({
      url: '/permission/parent',
      data: data
    })
  },
  // 添加权限
  add_permission(data) {
    return fetch({
      url: '/permission/add',
      data: data
    })
  },
  // 权限列表
  get_permission(data) {
    return fetch({
      url: '/permission/list',
      data: data
    })
  },
  get_permission_info(data) {
    return fetch({
      url: '/permission/info',
      data: data
    })
  },
  delete_permission(data) {
    return fetch({
      url: '/permission/delete',
      data: data
    })
  },
  role_list(data) {
    return fetch({
      url: '/role/list',
      data: data
    })
  },
  add_role(data) {
    return fetch({
      url: '/role/add',
      data: data
    })
  },
  role_info(data) {
    return fetch({
      url: 'role/info',
      data: data
    })
  },
  view_permissin(data) {
    return fetch({
      url: 'role/view_permission',
      data: data
    })
  },
  get_powers(data) {
    return fetch({
      url: 'get/powers',
      data: data
    })
  },
  get_user_info(data) {
    return fetch({
      url: 'user/info',
      data: data
    })
  },
  // 获取签名列表
  get_sign_list(data) {
    return fetch({
      url: 'get/sign',
      data: data
    })
  },
  add_sign(data) {
    return fetch({
      url: 'add/sign',
      data: data
    })
  },
  // 上传签名文件
  upload_file(data) {
    return fetch({
      url: 'upload/sign_file',
      data: data
    })
  },
  // 删除签名
  detach_sign(data) {
    return fetch({
      url: 'detach_sign',
      data: data
    })
  },
  game_channel(data) {
    return fetch({
      url: 'game_has_channel',
      data: data
    })
  },
  get_game_channel(data) {
    return fetch({
      url: 'get_game_channel',
      data: data
    })
  },
  // 获取渠道参数
  get_channel_params(data) {
    return fetch({
      url: 'get_channel_params',
      data: data
    })
  },
  // 更新绑定渠道参数
  save_params(data) {
    return fetch({
      url: 'save_params',
      data: data
    })
  },
  // 获取参数值
  get_params_value(data) {
    return fetch({
      url: 'get/params_value',
      data: data
    })
  },
  detach_channel(data) {
    return fetch({
      url: 'detach_channel',
      data: data
    })
  },
  add_game_version(data) {
    return fetch({
      url: 'add_game_version',
      data: data
    })
  },
  get_game_version(data) {
    return fetch({
      url: 'view_game_verify',
      data: data
    })
  },
  delete_game_version(data) {
    return fetch({
      url: 'delete_game_version',
      data: data
    })
  },
  get_channel_version(data) {
    return fetch({
      url: 'get_channel_version',
      data: data
    })
  },
  // 更新编译文件
  update_compile(data) {
    return fetch({
      url: 'update_compile',
      data: data
    })
  },
  get_tasks(data) {
    return fetch({
      url: 'get_tasks',
      data: data
    })
  },
  download_apk(data) {
    return fetch({
      url: 'download_apk' + data,
      method: 'get'
    })
  },
  // 获取未绑定的渠道
  get_exe_channel(data) {
    return fetch({
      url: 'get_exe_channel',
      data: data
    })
  }
}

